﻿using System.Collections.Generic;
using System.Threading.Tasks;
using AvaloniaMvvm.Helpers;
using AvaloniaMvvm.Models;
using SQLite;

namespace AvaloniaMvvm.Services.Impl;

public class PoetryStorage : IPoetryStorage
{
    // 语义明确的数据库文件名
    public const string DBName = "poetrydb.sqlite3";

    public static readonly string PoetryDbPath =
        PathHelper.GetLocalFilePath(DBName);

    // 传统做法
    private SQLiteAsyncConnection? _connection;

    private SQLiteAsyncConnection connection =>
        _connection ??= new SQLiteAsyncConnection(PoetryDbPath);
    
    // 套两层
    // {
    //     get
    //     {
    //         return _connection ??= new SQLiteAsyncConnection(PoetryDbPath);
    //     }
    // }
    
    // 套一层语法糖
    // {
    //     get
    //     {
    //         if (_connection is not null)
    //         {
    //             return _connection;
    //         }
    //         
    //         _connection = new SQLiteAsyncConnection(PoetryDbPath);
    //         return _connection;
    //     }
    // }

    public async Task InsertAsync(Poetry poetry)
    {
        // TODO:
        throw new System.NotImplementedException();
    }

    public async Task<IList<Poetry>> ListAsync()
    {
        // TODO:
        throw new System.NotImplementedException();
    }

    public async Task<IList<Poetry>> QueryAsync(string queryKeyword)
    {
        // TODO:
        throw new System.NotImplementedException();
    }
}